#!/bin/bash
# Manual Hostname Setup Commands for 5GC Testbed
# Run these commands one by one

echo "Setting hostname for VM1 (Core Network)..."
ssh vm1 << 'VM1_EOF'
sudo hostnamectl set-hostname vm1-5gc-core
sudo sed -i 's/127.0.1.1.*/127.0.1.1\tvm1-5gc-core/' /etc/hosts
echo "VM1 hostname set to: $(hostname)"
VM1_EOF

echo "Setting hostname for VM2 (UPF)..."
ssh vm2 << 'VM2_EOF'
sudo hostnamectl set-hostname vm2-5gc-upf
sudo sed -i 's/127.0.1.1.*/127.0.1.1\tvm2-5gc-upf/' /etc/hosts
echo "VM2 hostname set to: $(hostname)"
VM2_EOF

echo "Setting hostname for VM3 (gNodeB)..."
ssh vm3 << 'VM3_EOF'
sudo hostnamectl set-hostname vm3-5gc-gnb
sudo sed -i 's/127.0.1.1.*/127.0.1.1\tvm3-5gc-gnb/' /etc/hosts
echo "VM3 hostname set to: $(hostname)"
VM3_EOF

echo "Setting hostname for VM4 (UE)..."
ssh vm4 << 'VM4_EOF'
sudo hostnamectl set-hostname vm4-5gc-ue
sudo sed -i 's/127.0.1.1.*/127.0.1.1\tvm4-5gc-ue/' /etc/hosts
echo "VM4 hostname set to: $(hostname)"
VM4_EOF

echo "All hostnames set. Rebooting VMs..."
ssh vm1 'sudo reboot' &
ssh vm2 'sudo reboot' &
ssh vm3 'sudo reboot' &
ssh vm4 'sudo reboot' &

echo "Waiting 30 seconds for VMs to reboot..."
sleep 30

echo "Verifying hostnames..."
ssh vm1 'hostname'
ssh vm2 'hostname'
ssh vm3 'hostname'
ssh vm4 'hostname'

echo "Hostname setup complete!"
